import { BaseItem } from "../common/BaseItem";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { DataEvent } from "../../events/DataEvent";
import { CDBackPackItem } from "../../cache/CDItem/CDBackPackItem";
import { ItemData } from "../../resource/info/ItemData";
import { EDrug } from "../../../../Message/Public/EDrug";
import { Language } from "../../../../extend/language/Language";
import { DrugBagRecoveryConfig } from "../../resource/DrugBagRecoveryConfig";
import { PetUtil } from "../pet/info/PetUtil";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { SDrugBagInfo } from "../../../../Message/Game/SDrugBagInfo";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { Cache } from "../../cache/Cache";
import { PetDrugItemInfo } from "./PetDrugItemInfo";
type int = number;
//class PetDrugBagItem
    
    export  class PetDrugBagItem extends BaseItem
    {
        constructor()
        {
            super();
            this.setSize(17, 17);
            this.isDragAble = false;
            this.isDropAble = false;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._bgBitmap = new Object /* flash.display.Bitmap */();
            this.addChildAt(this._bgBitmap, 0);
            freezingEffect.setMaskSize(18, 18);
            Dispatcher.addEventListener(EventName.ItemUse, this.onItemUseingHandler);
            return;
        }

        /* internal  */onItemUseingHandler(arg1: DataEvent): void
        {
            if (this._drugBagData == null) 
            {
                if (freezingEffect.isCDPlaying) 
                {
                    freezingEffect.clearEffect();
                }
                return;
            }
            var loc1=arg1.data as CDBackPackItem;
            if (loc1) 
            {
                if (freezingEffect.isCDPlaying == false && loc1.isCanCd(itemData)) 
                {
                    freezingEffect.cdTime = loc1;
                }
            }
            else if (freezingEffect.isCDPlaying) 
            {
                freezingEffect.clearEffect();
            }
            return;
        }

        public /* override */ set itemData(arg1: ItemData)
        {
            _itemData = arg1;
            return;
        }

        public /* override */ get toolTipData()
        {
            var loc4=0;
            var loc5=0;
            if (!this._petDrugItemInfo) 
            {
                return "";
            }
            var loc1="";
            var loc2="";
            var loc3=2000;
            if (this.drugBagData) 
            {
                if (this.drugBagData.type != EDrug._EDrugLifePetBag) 
                {
                    loc2 = Language.getString(50032);
                }
                else 
                {
                    loc2 = Language.getString(50031);
                    loc5 = this._petDrugItemInfo.maxLife;
                }
                loc4 = DrugBagRecoveryConfig.instance.getConfigByLevel(this.drugBagData.type, PetUtil.getFourDigitLevel(this._petDrugItemInfo.reinLevel, this._petDrugItemInfo.level), true);
                loc3 = int(loc4 / 1000) + int(loc4 % 1000 / 100 * loc5);
                loc1 = loc1 + Language.getStringByParam(50033, loc2, loc2, loc2, loc2, loc3, loc2, this.drugBagData.remain, "");
                loc1 = HTMLUtil.addColor(loc1, "#B1efff") + "\r\r";
                return loc1;
            }
            return null;
        }

        public get drugBagData(): SDrugBagInfo
        {
            return this._drugBagData;
        }

        public set drugBagData(arg1: SDrugBagInfo)
        {
            this._drugBagData = arg1;
            if (arg1) 
            {
                if (arg1.type == EDrug._EDrugLifePetBag) 
                {
                    if (this._bagType != arg1.type) 
                    {
                        this._bagType = arg1.type;
                        this._bgBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.LifeDrugBag);
                        this._bgBitmap.width = 17;
                        this._bgBitmap.height = 17;
                        this.itemData = Cache.instance.timeCdCache.petLifeCD.itemData;
                    }
                    if (Cache.instance.timeCdCache.petLifeCD.isCoolDown == false) 
                    {
                        freezingEffect.cdTime = Cache.instance.timeCdCache.petLifeCD;
                    }
                }
            }
            else 
            {
                this._bgBitmap.bitmapData = null;
                freezingEffect.clearEffect();
                this._bagType = -1;
            }
            return;
        }

        public /* override */ setSize(arg1: number, arg2: number): void
        {
            super.setSize(arg1, arg2);
            if (freezingEffect) 
            {
                freezingEffect.x = 8;
                freezingEffect.y = 8;
            }
            return;
        }

        public get petDrugItemInfo(): PetDrugItemInfo
        {
            return this._petDrugItemInfo;
        }

        public set petDrugItemInfo(arg1: PetDrugItemInfo)
        {
            this._petDrugItemInfo = arg1;
            return;
        }

        /* internal */ /* var */_bgBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_drugBagData: SDrugBagInfo;

        /* internal */ /* var */_petDrugItemInfo: PetDrugItemInfo;

        /* internal */ /* var */_bagType: int=-1;
    }
